package com.example.demo.dao;

import com.example.demo.VO.ClazzExtra;
import com.example.demo.core.Mapper;
import com.example.demo.model.Clazz;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author Kevin
 * @date 2020/4/19 15:36
 */
public interface ClazzMapper extends Mapper<Clazz> {
    /**
     *  查询班级信息（附带班级所有学生）
     */
    @Select("SELECT * FROM tb_clazz WHERE id = #{id} limit 1")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "code", property = "code"),
            @Result(column = "name", property = "name"),
            @Result(column = "id", property = "students",
                many = @Many(
                        select = "com.example.demo.dao.StudentMapper.queryStudentInfoByClazz",
                        fetchType = FetchType.LAZY
                ))
    })
    public ClazzExtra queryClazzInfoWithStudent(Integer id);
}
